﻿using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkitMvvmDemo.Models;
using LiveCharts;
using LiveCharts.Defaults;
using LiveCharts.Wpf;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CommunityToolkitMvvmDemo.ViewModels
{
  public partial  class HomePageViewModel:ObservableObject
    {
        [ObservableProperty]
        private int curentValue;

        [ObservableProperty]
        private ObservableCollection<Student> students;

        [ObservableProperty]
        private int  itemCount;

        Random random = new Random();
        public HomePageViewModel()
        {
            Task.Run(async () =>
            {
                while (true)
                {
                    CurentValue = random.Next(this.CurentValue - 15, this.curentValue + 15);
                    await Task.Delay(1000);
                }
            });


            Students = new ObservableCollection<Student>();
            Students.Add(new Student
            {
                CourseName = "课程1",
                SeriesCollection = new LiveCharts.SeriesCollection {
                    new PieSeries {
                     Title="标题1",
                     Values =new ChartValues<ObservableValue>{ new ObservableValue(123)},
                      DataLabels = false
                 },  new PieSeries {
                     Title="标题2",
                     Values =new ChartValues<ObservableValue>{ new ObservableValue(123)},
                      DataLabels = false
                 },new PieSeries {
                     Title="标题3",
                     Values =new ChartValues<ObservableValue>{ new ObservableValue(123)},
                      DataLabels = false
                 }},
                SeriesList = new ObservableCollection<SeriesModel>
                 {
                     new SeriesModel { SeriesName="云课堂11",value=111, IsGrowing = false,  ChangeRate=15  },
                     new SeriesModel { SeriesName="云课堂12",value=222, IsGrowing = true,  ChangeRate=25  },
                     new SeriesModel { SeriesName="云课堂13",value=333, IsGrowing = true,  ChangeRate=35  },
                     new SeriesModel { SeriesName="云课堂14",value=444, IsGrowing = false,  ChangeRate=45  },
                     new SeriesModel { SeriesName="云课堂15",value=555, IsGrowing = false,  ChangeRate=55  },
                      new SeriesModel { SeriesName="云课堂16",value=666, IsGrowing = false,  ChangeRate=66  }
                 }
            });
            Students.Add(new Student
            {
                CourseName = "课程2",
                SeriesCollection = new LiveCharts.SeriesCollection {
                    new PieSeries {
                     Title="标题2",
                     Values =new ChartValues<ObservableValue>{ new ObservableValue(123)},
                      DataLabels = false
                 }, new PieSeries {
                     Title="标题2",
                     Values =new ChartValues<ObservableValue>{ new ObservableValue(123)},
                      DataLabels = false
                 }},
                SeriesList = new ObservableCollection<SeriesModel>
                 {
                     new SeriesModel { SeriesName="云课堂21",value=111, IsGrowing = false,  ChangeRate=15  },
                     new SeriesModel { SeriesName="云课堂22",value=222, IsGrowing = true,  ChangeRate=25  },
                     new SeriesModel { SeriesName="云课堂23",value=333, IsGrowing = true,  ChangeRate=35  }
                 }
            });
            Students.Add(new Student
             {
                 CourseName = "课程3",
                 SeriesCollection = new LiveCharts.SeriesCollection {
                    new PieSeries {
                     Title="标题3",
                     Values =new ChartValues<ObservableValue>{ new ObservableValue(123)},
                      DataLabels = false
                 }, new PieSeries {
                     Title="标题3",
                     Values =new ChartValues<ObservableValue>{ new ObservableValue(123)},
                      DataLabels = false
                 }},
                 SeriesList = new ObservableCollection<SeriesModel>
                 {
                     new SeriesModel { SeriesName="云课堂31",value=111, IsGrowing = false,  ChangeRate=15  },
                     new SeriesModel { SeriesName="云课堂32",value=222, IsGrowing = true,  ChangeRate=25  },
                     new SeriesModel { SeriesName="云课堂33",value=333, IsGrowing = true,  ChangeRate=35  },
                     new SeriesModel { SeriesName="云课堂34",value=444, IsGrowing = false,  ChangeRate=45  },
                     new SeriesModel { SeriesName="云课堂35",value=555, IsGrowing = false,  ChangeRate=55  }
                 }
             } );

            this.ItemCount = Students.Max(i=> i.SeriesList.Count());
        }


 
    }
}
